<?php
namespace common\modules\content\models\search;

use common\modules\content\models\ArticleCategory;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;


/**
 * ArticleCategorySearch represents the model behind the search form about `common\models\ArticleCategory`.
 */
class ArticleCategorySearch extends ArticleCategory
{

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                [
                    'id',
                    'status'
                ],
                'integer'
            ],
            [
                [
                    'slug',
                    'title'
                ],
                'safe'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     * 
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = ArticleCategory::find();
        
        $dataProvider = new ActiveDataProvider([
            'query' => $query
        ]);
        
        if (! ($this->load($params) && $this->validate())) {
            return $dataProvider;
        }
        
        $query->andFilterWhere([
            'id' => $this->id,
            'status' => $this->status
        ]);
        
        $query->andFilterWhere([
            'like',
            'slug',
            $this->slug
        ])->andFilterWhere([
            'like',
            'title',
            $this->title
        ]);
        
        return $dataProvider;
    }
}
